home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HAM Radio 1997
/
HAM Radio 1997.iso
/
vcls
/
useful
/
useful.pas
next >
Wrap
Pascal/Delphi Source File
|
1996-04-08
|
4KB
|
119 lines
{
========
Newsgroups: comp.lang.pascal.delphi.components
Subject: Usefule Delphi Unit
From: Jan Rochat <rochat@xs4all.nl>
Date: 24 Aug 1995 18:27:32 GMT
The following unit contains some useful routines for delphi-users.
The first two routine are for use with an DropDown Combobox. The routine
DropDownListSelection returns the current selected item of the dropDownComboBox
If no slection was made the routine returns an empty string ('').
The second routine will select a string from a dropdowncombobox. If the string
given is not available in the dropdown list then no selection will be made.
The last routine is for use with an TabbedNotebook component.The routine will
set the focus on the given control (component), by first making the tabPage that
contains the comtrol the visible page, and then setting the focus to the control.
If the specified control is noton the TabbedNotebook no changes (focussing) will
be made.
Any reactions on these routines are always welcome,
}
unit Useful;
interface
uses StdCtrls, TabNotBk, Classes;
function GetDropDownListSelection(cbList: TComboBox): string;
procedure SetDropDownListSelection(cbList: TComboBox; Selection: string);
procedure FocusTabbedNotebookControl(NoteBook: TTabbedNotebook; Control: TComponent);
implementation
uses
Controls, SysUtils;
function GetDropDownListSelection(cbList: TComboBox): string;
var
Index : Integer;
begin
Result := '';
if cbList.Style = csDropDownList then
begin
Index := cbList.ItemIndex;
If Index >= 0 then Result := cbList.Items.Strings[Index];
end;
end;
procedure SetDropDownListSelection(cbList: TComboBox; Selection: string);
var
Index : Integer;
begin
Index := cbList.Items.IndexOf(Selection);
If Index >= 0 then cbList.ItemIndex := Index;
end;
procedure FocusTabbedNotebookControl(NoteBook: TTabbedNotebook; Control: TComponent);
var
Index, I : Integer;
Found : Boolean;
TabPage : TTabPage;
function ControlPresent( OwnerControl: TControl; ControlToSearchFor: string): Boolean;
var
Index: Integer;
Found: Boolean;
Ctl: TWinControl;
begin
Found := False;
if OwnerControl is TWinControl then
begin
Ctl := TWinControl(OwnerControl);
if Ctl.ControlCount = 0
then Found := CompareText( OwnerControl.Name, ControlToSearchFor) = 0
else
begin
index := 0;
while (not found) and (index < Ctl.ControlCount) do
begin
Found := ControlPresent(Ctl.Controls[Index], ControlToSearchFor);
Inc(Index);
end;
end;
end;
Result := Found;
end; {ControlPresent}
begin {FocusTabbedNotebookControl}
if Control is TWinControl then
begin
if not TWinControl(Control).CanFocus then
begin
found := False;
for index := 0 to NoteBook.Pages.Count-1 do
begin
TabPage := TTabPage(NoteBook.Pages.Objects[index]);
for i := TabPage.ControlCount-1 downto 0 do
begin
Found := ControlPresent(TabPage.Controls[i], Control.Name);
if found then NoteBook.PageIndex := Index;
end;
end;
end;
if TWinControl(Control).CanFocus then TWinControl(Control).SetFocus;
end;
end; {FocusTabbedNotebookControl}
end.